home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C14 / Protect.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  604 b   |  31 lines

  1. //: C14:Protect.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // The protected keyword
  7. #include <fstream>
  8. using namespace std;
  9.  
  10. class Base {
  11.   int i;
  12. protected:
  13.   int read() const { return i; }
  14.   void set(int ii) { i = ii; }
  15. public:
  16.   Base(int ii = 0) : i(ii) {}
  17.   int value(int m) const { return m*i; }
  18. };
  19.  
  20. class Derived : public Base {
  21.   int j;
  22. public:
  23.   Derived(int jj = 0) : j(jj) {}
  24.   void change(int x) { set(x); }
  25. }; 
  26.  
  27. int main() {
  28.   Derived d;
  29.   d.change(10);
  30. } ///:~
  31.